package com.xyp.danmu.controller;

import com.xyp.danmu.model.Message;
//import com.xyp.danmu.utils.RedisDBHelperImpl;
import com.xyp.danmu.utils.JsonMapper;
import com.xyp.danmu.utils.RedisDBHelperImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;

/**
 * @author xuyuanpeng
 * @version 1.0
 * @date 2019-02-27 20:10
 */
@RequestMapping("test")
@Controller
public class TestController {
    @Autowired
    private RedisDBHelperImpl redisDBHelper;

    @RequestMapping("/listFindAll")
    @ResponseBody
    public Object listFindAll(String key){
        Object obj=redisDBHelper.listFindAll(key);
        if(obj==null){return "error not found value by Key";}
        return  obj  ;
    }

    @RequestMapping("/hashFindAll")
    @ResponseBody
    public Object hashFindAll(String key){
        Object obj=redisDBHelper.hashFindAll(key);
        if(obj==null){return "error not found value by Key";}
        return  obj  ;
    }

    @RequestMapping("/hashPut")
    @ResponseBody
    public Object put(@RequestBody @Valid Message message){
        redisDBHelper.hashPut(message.getUid(),message.getUid(),message.getContent());
        return true;
    }
    @RequestMapping("/listPush")
    @ResponseBody
    public Object listPush(@RequestBody @Valid Message message){
        String time=String.valueOf(System.currentTimeMillis());
        redisDBHelper.listPush(time, JsonMapper.toJsonString(message));
        return time;
    }
}
